<template>
  <a-card :bordered="false">
     <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="到期天数">
              <a-input-number placeholder="请输入到期天数"  :precision="0" v-model="queryParam.date"  style="width:100%" addon-after="天" ></a-input-number>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="到期日期">
              <j-date  placeholder="请选择到期日期" v-model="queryParam.endDate"  style="width: 100%" ></j-date>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <!-- <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button> -->
          <a-button v-else icon="download" @click="viewFile(text)">文件列表</a-button>
        </template>

        
      </a-table>
    </div>

    <view-file-modal ref="viewFileModal"></view-file-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import { viewFile } from '@/utils/util'
  import ViewFileModal from '@/views/scy/components/ViewFileModal'
  import { initDictOptions } from '@/components/dict/JDictSelectUtil'
  import moment from 'moment'


  export default {
    name: 'ErpEmployeeCertificateList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin,viewFile],
    components: {
      ViewFileModal
    },
    props:{
      disabledButton:{
        type: Boolean,
        default: false
        
      },
      newData: {
        type: Array,
        default: () => []
      }
    },
    data () {
      return {
        description: '资质证书管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        queryParam:{
          date:45
        },
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'姓名',
            align:"center",
            width:100,
            dataIndex: 'name',
          },
          // {
          //   title:'所属单位',
          //   align:"center",
          //   dataIndex: 'orgDepart',
          //   customRender: (text) => {
          //   if (!text) {
          //     return ''
          //   } else {
          //     return filterMultiDictText(this.dictOptions['orgDepart'], text + '')
          //   }
          // }
          // },
          // {
          //   title:'所属部门',
          //   align:"center",
          //   dataIndex: 'departmentId',
          //   customRender: (text) => {
          //   if (!text) {
          //     return ''
          //   } else {
          //     return filterMultiDictText(this.dictOptions['departmentId'], text + '')
          //   }
          // }
          // },
          {
            title:'证书名称',
            align:"center",
            width:200,
            dataIndex: 'certificateName',
          },
          {
            title:'颁布时间',
            align:"center",
            width:200,
            dataIndex: 'issueDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
            
          },
          {
            title:'颁发机构',
            align:"center",
            width:200,
            dataIndex: 'issueBody',
          },
          {
            title:'到期时间',
            align:"center",
            width:200,
            dataIndex: 'endDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'到期天数',
            align:"center",
            width:200,
            dataIndex: 'date',
            customRender:function (text,record) {
              return moment(record.endDate).diff(moment().format('YYYY-MM-DD'), 'days');
            }
          },
          {
            title:'附件',
            align:"center",
            width:200,
            dataIndex: 'attachment',
            scopedSlots: {customRender: 'fileSlot'}
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: {
          //   filterDropdown: 'filterDropdown',
          //   filterIcon: 'filterIcon',
          //   customRender: 'action'
          //   }
          // }
        ],
        url: {
          list: "/api/erp/files/employee/erpEmployeeCertificate/certificateList",
        },
        dictOptions:{},
        superFieldList:[],
        colsettings:'ErpEmployeeCertificate:colsettings',
      }
    },
    created() {
      this.getSuperFieldList();
      this.loadData();
      this.initColumns();
      this.initDictConfig();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      searchReset() {
      this.queryParam = {
        date:45
      }
      this.loadData(1)
    },
      async initDictConfig(){
        initDictOptions('sys_depart,depart_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'orgDepart', res.result)
            this.$set(this.dictOptions, 'departmentId', res.result)
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'certificateName',text:'证书名称',dictCode:''})
        fieldList.push({type:'string',value:'issueBody',text:'颁发机构',dictCode:''})
        fieldList.push({type:'string',value:'attachment',text:'附件',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
